<template>
  <div>
    <MyHeaderVue background="red" title="这是标题" color></MyHeaderVue>
    <div class="fixd"><MyGoodsVue v-for="obj in list" :key="obj.id" :obj="obj"></MyGoodsVue></div>
    <MyFooterVue @obj="lista" :list="list"></MyFooterVue>
  </div>
</template>

<script>
  //引入子组件
  import MyHeaderVue from './components/MyHeader.vue';
  import MyGoodsVue from './components/MyGoods.vue';
  import MyFooterVue from './components/MyFooter.vue';
export default {
  data(){
    return{
      list:[]
    }
  },
  methods:{
    //循环list 数组
    lista(a){
      this.list.forEach(itms =>{
        //使用子组件传过来的全选按钮状态赋值给每一项
            itms.goods_state = a
          })
  }
},
 components:{
  //注册引入过来的子组件
  MyHeaderVue,
  MyGoodsVue,
  MyFooterVue
 },
 created(){
  //发起axios请求获取数据
  this.$axios({url:'/api/cart'
}).then(res =>{
  const {data:{list}} =res
  //将获取过来的数据赋值给组件中的list
  this.list = list
})
 },
 
}
</script>

<style>
.fixd{
  padding-top: 45px;
  padding-bottom: 50px;
}
</style>